#ifndef I_CONNECTION_LISTERNER_H
#define I_CONNECTION_LISTERNER_H

#include "u_peer.h"

class IConnectionListener
{
public:
	virtual void onConnectionLost(UPeer::Ptr upeer){}
	virtual void onNewConnectionConnected(UPeer::Ptr upeer) {}
	virtual void onConnectionEstablished(UPeer::Ptr upeer){}
	virtual ~IConnectionListener(){}
	typedef boost::shared_ptr<IConnectionListener> Ptr;
};

typedef boost::function<void(UPeer::Ptr)> ConnectionDelegate;

class ConnectionListenerProxy : public IConnectionListener
{
	ConnectionDelegate lostDelegate_;
	ConnectionDelegate connectedDelegate_;
	ConnectionDelegate establieshedDelegate_;
public:
	inline void setConnectionLostDelegate(ConnectionDelegate callback)
	{
		lostDelegate_ = callback;
	}

	inline void setConnectedDelegate(ConnectionDelegate callback)
	{
		connectedDelegate_ = callback;
	}

	inline void setEstablishedDelegate(ConnectionDelegate callback)
	{
		establieshedDelegate_ = callback;
	}

	virtual void onConnectionLost(UPeer::Ptr upeer){if(lostDelegate_)lostDelegate_(upeer);}
	virtual void onNewConnectionConnected(UPeer::Ptr upeer) {if(connectedDelegate_)connectedDelegate_(upeer);}
	virtual void onConnectionEstablished(UPeer::Ptr upeer){if(establieshedDelegate_)establieshedDelegate_(upeer);}
};

#endif
